var express = require('express')

var router = express.Router()

// 导入MySQL模
var mysql = require('mysql')

var mysqlConfig = require('../../config/mysql')

// 连接池
var pool = mysql.createPool(mysqlConfig)

//登录
router.get('/', (req, res, next) => {
    pool.getConnection((err, connection) => {

        //参数
        const {
            user_account
        } = req.query

        if (user_account) {

            connection.query(`SELECT * FROM user_table WHERE user_account = "${user_account}"`, (err, result) => {
                if (!err && result.length > 0) {
                    results = {
                        code: 200,
                        msg: '登录成功',
                        data: result[0]
                    };
                    res.json(results)
                } else {
                    res.json({
                        code: 500,
                        msg: '登录失败',
                        err
                    });
                }
                connection.release()
            })

        } else {
            res.json({
                code: 500,
                msg: '登录失败',
                err
            });
        }

    })
})

module.exports = router